<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection"
	content="telephone=no,email=no,date=no,address=no">
<title></title>
<link rel="stylesheet" type="text/css" href="../css/aui.css" />
<link rel="stylesheet" type="text/css"
	href="../css/aui-pull-refresh.css" />
<style>
.aui-content-padded {
	padding: 0.75 rem;
	background-color: #ffffff;
	margin-top: 0.75 rem;
}

.aui-card-list-footer>* {
	position: absolute;
	right: 30px;
	bottom: 10px;
}
</style>
</head>
<body>
	<header class="aui-bar aui-bar-nav aui-bar-warning" id="aui-header">
	<a class="aui-pull-left" onclick="window.history.back(-1);"> <span
		class="aui-iconfont aui-icon-left"></span>
	</a>
	<div class="aui-title">修改密码</div>
	<a class="aui-pull-right"> </a> </header>
	
	
		<section class="aui-content" >
			<ul class="aui-list aui-list-in aui-margin-b-15">
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<input type="password" id="password" placeholder="请输入密码">
					</div>
				</li>
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<input type="text" id="pwdCode" placeholder="请输入验证码">
					</div>
					<div class="aui-list-item-label-icon" style="padding-right: 2rem;" >
						<input type="button" class="aui-btn aui-btn-info" style="margin-right: 0.5rem;" id="btn" value="获取验证码" onclick="settime(this)" />
					</div>
				</li>
			</ul>
			<div class="aui-btn aui-btn-primary aui-btn-block" style="margin: 0 auto;width: 95%;" onclick="submitPassword()" >
				提交
			</div>
		</section>	
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery.qrcode.min.js"></script>
<script type="text/javascript" src="../js/aui-dialog.js" ></script>

<script type="text/javascript">
	//得到选择机会信息的id
	var id = "${param.id}";
	
	
	/**
	 *转换时间格式yyyy-MM-dd
	 */
	function toDate(data) {
		var date = new Date(data);
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		m = m < 10 ? '0' + m : m;
		var d = date.getDate();
		d = d < 10 ? ('0' + d) : d;
		return y + '-' + m + '-' + d;
	}
	
	
	function settime(val) {
			if (countdown == 0) {
				val.removeAttribute("disabled");
				$("#btn").addClass("aui-btn-info");
				$("#btn").removeClass("aui-btn-default");
				val.value = "获取验证码";
				countdown = 60;
			} else {
				if (countdown == 60) {
					$.ajax({
						url : '${pageContext.request.contextPath}/appcrm/getPhoneCode.do',
						type : "POST",
						dataType : "json",
						data : {
							"type" : "1",
							"phone" : "15622774543" //取当前用户的手机号码，如果没有应跳转到绑定手机页面。
						},
						success : function(data) {
							if (data.code == "0") {
								//发送成功
							}else {
								alert("发送失败！请稍后在发送！");
							}
						}
					});
				}
				val.setAttribute("disabled", true);
				$("#btn").addClass("aui-btn-default");
				$("#btn").removeClass("aui-btn-info");
				val.value = "重新发送(" + countdown + ")";
				countdown--;
				setTimeout(function() {
					settime(val)
			}, 1000)
		}
	}




	function submitPassword() {
			var password = $("#password").val().trim();
			if (password == "") {
				dialog.alert({
					msg : '请输入密码!',
					buttons : ['取消', '确定']
				}, function(ret) {
					console.log(ret)
				})
				return false;
			}
			var pwdCode = $("#pwdCode").val().trim();
			if (pwdCode == "") {
				dialog.alert({
					msg : '请输入验证码!',
					buttons : ['取消', '确定']
				}, function(ret) {
					console.log(ret)
				})
				return false;
			}
			$("#loading").show();

			$.ajax({
				url : '${pageContext.request.contextPath}/appcrm/getPhoneCodeUpdatePwd.do',
				type : "POST",
				dataType : "json",
				data : {
					"password" : password,
					"pwdCode" : pwdCode //取当前用户的手机号码，如果没有应跳转到绑定手机页面。
				},
				success : function(data) {
					$("#loading").hide();
					if (data.code == 0) {
						alert("重置成功！");
					} else if (data.code == 1) {
						alert("验证码不正确！");
					} else {
						alert("服务器忙！");
					}
				}
			});
	}





</script>
</html>